<?php 
namespace app\admin\controller;
class Index extends Common {

	public function index(){
		return $this -> html($this -> fetch());
	}

	public function main(){
		return $this -> html($this -> fetch());
	}

	public function password(){
		if (\Ebcms::isPost()) {
			if (!$old_password = \mylib\Input::post('old_password')) {
				return $this -> error('请输入旧密码！');
			}
			if (!$password = \mylib\Input::post('password')) {
				return $this -> error('请输入新密码！');
			}
			if (strlen($password) < 6) {
				return $this -> error('密码最少6位！');
			}
			if ($old_password != \mylib\Config::get('admin.password')) {
				return $this -> error('旧密码不正确！');
			}
			file_put_contents(PROJECT_PATH . 'app/admin/config/admin.php', '<?php '.PHP_EOL.'return ' . var_export([
				'account'=>\mylib\Config::get('admin.account'),
				'password'=>$password,
			], true) . ';');
			return $this -> success('密码修改成功！');
		}else{
			return $this -> html($this -> fetch());
		}
	}
}